package com.homedo.microservice.open.service.gateway.manager.web.service;

import com.google.common.collect.Lists;
import com.homedo.common.bean.vo.context.UserContext;
import com.homedo.common.dao.bean.po.base.BasePo;
import com.homedo.common.service.BaseService;
import com.homedo.common.util.Detect;
import com.homedo.microservice.open.service.gateway.manager.web.bean.po.UserLoginLog;
import com.homedo.microservice.open.service.gateway.manager.web.bean.po.enhanced.UserLoginLogEnhanced;
import com.homedo.microservice.open.service.gateway.manager.web.persistence.dao.UserLoginLogDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 作者 jgshun
 * @date 创建时间 2018年10月19日 11时22分20秒
 */
@Service
public class UserLoginLogService extends BaseService<UserLoginLog> {
    @Autowired
    private UserLoginLogDao userLoginLogDao;


    @Override
    public List<UserLoginLogEnhanced> getEnhanceds(List<?> ids, UserContext userContext) {
        List<UserLoginLog> userLoginLogs = userLoginLogDao.getListByIds(ids, UserLoginLog.class);

        if (!Detect.notEmpty(userLoginLogs)) {
            return null;
        }

        return this.convent2Enhanceds(userLoginLogs);
    }


    @Override
    public List<UserLoginLogEnhanced> getEnhanceds4Active(List<?> ids, UserContext userContext) {
        List<UserLoginLog> userLoginLogs = userLoginLogDao.getListByIdsGreaterThanMark0(ids, UserLoginLog.class);

        if (!Detect.notEmpty(userLoginLogs)) {
            return null;
        }

        return this.convent2Enhanceds(userLoginLogs);
    }


    @Override
    public List<UserLoginLogEnhanced> convent2Enhanceds(List<? extends BasePo> pos) {
        List<UserLoginLog> userLoginLogs = (List<UserLoginLog>) pos;
        List<UserLoginLogEnhanced> userLoginLogEnhanceds = Lists.newArrayList();
        userLoginLogs.forEach(e -> userLoginLogEnhanceds.add(new UserLoginLogEnhanced(e)));
        return userLoginLogEnhanceds;
    }


}
